import * as Cesium from 'cesium';
var viewer = null;
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIwOTc0OWZiMC1kYWFkLTQ3Y2QtODQyNC0wNTdkMTdmMTk4MTEiLCJpZCI6MjIzMTMsImlhdCI6MTYwMjUzOTUxNH0.r18dBOtxmRRuiYcogILHfk3TN7lGrgOfTDSxIYxO9hY';

function setviewer(e) {
    viewer = new Cesium.Viewer(e, {
        animation: false,//左下角控制动画
        baseLayerPicker: false,//右上角图层选择器
        fullscreenButton: false,
        geocoder: false,//右上角搜索            
        homeButton: false,
        infoBox: false,
        scene3DOnly: true, //仅仅显示3d,可隐藏右上角2d和3d按钮 
        selectionoIndicatr: false,
        timeline: true,//最下面时间轴            
        navigationHelpButton: false,//右上角帮助按钮 
        navigationInstructionsInitiallyVisibl: false,
        useDefaultRenderLoop: true,
        showRenderLoopErrors: true,
        projectionPicker: false,
        shouldAnimate: true
    });
    
}
function mapset() {
    viewer.timeline.container.style.display = 'none';
    var stages = viewer.scene.postProcessStages;
    viewer.scene.brightness = viewer.scene.brightness || stages.add(Cesium.PostProcessStageLibrary.createBrightnessStage());
    viewer.scene.brightness.enabled = true;
    viewer.scene.brightness.uniforms.brightness = Number(1.2);
    viewer.scene.globe.depthTestAgainsTerrain = false;
    var CesiumViewerSceneController = viewer.scene.screenSpaceCameraController;
    CesiumViewerSceneController.inertiaSpin = 0.95;
    CesiumViewerSceneController.inertiaTranslate = 0.95;
    CesiumViewerSceneController.inertiaZoom = 0.9;

    viewer.scene.postProcessStages.fxaa.enabled = true;
    var supportsImageRenderingPixelated = viewer.cesiumWidget._supportsImageRenderingPixelated;
    if (supportsImageRenderingPixelated) {
        var vtxf_dpr = window.devicePixelRatio;
        while (vtxf_dpr >= 2.0) { vtxf_dpr /= 2.0; }
        viewer.resolutionScale = vtxf_dpr;
    }

    viewer.scene.globe.baseColor = new Cesium.Color(0, 0.02, 0.23, 1.0);
    Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(80, 22, 130, 50);
    viewer.scene.skyBox.show = true;
}
function layset() {
    viewer.imageryLayers.remove(viewer.imageryLayers.get(0));
    var weixingMap = new Cesium.UrlTemplateImageryProvider({
        url: "http://wx.henangis.com/map.aspx?T=JG&Z={z}&Y={y}&X={x}",
        tilingScheme: new Cesium.WebMercatorTilingScheme(),
        minimumLevel: 1,
        maximumLevel: 20
    });
    viewer.imageryLayers.addImageryProvider(weixingMap);

    var dzmap = 'http://gis.henangis.com/mktxyz.aspx?T=SUPERGIS&z={z}&x={x}&y={y}';
    viewer.imageryLayers.addImageryProvider(
        new Cesium.UrlTemplateImageryProvider({
            url: dzmap,
            tilingScheme: new Cesium.WebMercatorTilingScheme()
        })
    );
    var m_temp_source = new Cesium.CustomDataSource("tempSourceLayer");
    viewer.dataSources.add(m_temp_source);

    viewer.camera.setView({
        destination: Cesium.Cartesian3.fromDegrees(113.82, 34.03, 1600000.0),
        orientation: {
            roll: 0.0
        }
    });
}

export default {
    setviewer,mapset,layset
}